//
//  LoadIndicator.m
//  Comma
//
//  Created by 刘轩博 on 15/1/28.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "LoadIndicator.h"
#import "GlobalMacro.h"
@implementation LoadIndicator
/*数据加载风火轮*/
+ (void)addIndicatorInView:(UIView *)inView
{
    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    indicator.center = inView.center;
    indicator.tag = 999;
    [inView addSubview:indicator];
    [indicator startAnimating];
    
    
}

/*停止风火轮*/
+ (void)stopAnimationInView:(UIView *)inView
{
    UIActivityIndicatorView *indicator = (UIActivityIndicatorView *)[inView viewWithTag:999];
    [indicator stopAnimating];
}

- (void)addLoadView:(UIView *)inView
{
    self.imgView = [[UIImageView alloc] initWithImage:[UIImage  imageNamed:@"Loading2.pdf"]];
    _imgView.frame = CGRectMake((SCREEN_WIDTH - 40)/2, SCREEN_HEIGHT * 2/ 5, 40, 24);
    if (iPhone5) {
        _imgView.frame = CGRectMake(SCREEN_WIDTH / 2 - 20 *0.85, SCREEN_HEIGHT * 2 / 5, 32 * 0.85, 10*0.85);
    }
    if (iPhone6Plus) {
        _imgView.frame = CGRectMake(SCREEN_WIDTH / 2 - 20 *1.656, SCREEN_HEIGHT * 2 / 5, 32 * 1.656, 10*1.656);
    }
    [self addAnimation];
    [inView addSubview:self.imgView];
    
}

///  动画停止
- (void)stopAnimationLoadView
{
    [self.imgView removeFromSuperview];
}

/// 添加动画
- (void)addAnimation
{
    CABasicAnimation *monkeyAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    monkeyAnimation.toValue = [NSNumber numberWithFloat:5.0 *M_PI];
    monkeyAnimation.duration = 1.0f;
    monkeyAnimation.repeatCount = 10000;
    monkeyAnimation.cumulative = NO;
    monkeyAnimation.removedOnCompletion = NO; //No Remove
    [self.imgView.layer addAnimation:monkeyAnimation forKey:@"AnimatedKey"];
    
}

+ (void)networkStateNotReachableInView:(UIView *)view
{
    CGSize size = view.frame.size;
    UIImageView *imgView = [[UIImageView alloc] init];
    UIImage * image = [UIImage imageNamed:@"networklost"];
    CGSize imageSize = image.size;
    imgView.image = image;
    CGFloat left = (size.width - imageSize.width) / 2;
    CGFloat up = (size.height - imageSize.height) / 2;
    [imgView setFrame:CGRectMake(left, up, imageSize.width, imageSize.height)];
    [view addSubview:imgView];
    [view bringSubviewToFront:imgView];
}
@end
